<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('考勤组人员列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <li>
                            <label>用户类型：</label>
                            <select name="userType">
                                <option value="">所有</option>
                                <option value="-1">代码生成请选择字典属性</option>
                            </select>
                        </li>
                        <li>
                            <label>用户姓名：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="selectStudent()" shiro:hasPermission="school:group:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="school:group:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('school:group:edit')}]];
    var removeFlag = [[${@permission.hasPermi('school:group:remove')}]];
    var userTypeDatas = [[${@dict.getType('sc_user_type')}]];
    var prefix = ctx + "school/attendance/group";
    var groupId = [[${groupId}]];
    function selectStudent(){
        var url = ctx + "school/student/query";
        var options = {
            title: '选择学生信息',
            width: "800",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var table = layero.find("iframe")[0].contentWindow.$.table;
        var studentId = table.selectColumns("id");
        if(studentId.length == 0){
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        var studentName = table.selectColumns("studentName");

        var data = {"userIds":studentId.join(),"userNames":studentName.join(),"groupId":groupId};

        $.operate.post(prefix + "/addUser", data);


        layer.close(index);
    }
    $(function() {
        var options = {
            url: prefix + "/getGroupUserList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/removeGroupUer",
            modalName: "考勤组人员",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id主键',
                    visible: false
                },
                {
                    field: 'groupId',
                    title: '考勤组名称'
                },
                {
                    field: 'schoolId',
                    title: '学校id'
                },
                {
                    field: 'userId',
                    title: '用户id'
                },
                {
                    field: 'userType',
                    title: '用户类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(userTypeDatas, value);
                    }
                },
                {
                    field: 'userName',
                    title: '用户姓名'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>